﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AliboboStockLib.linq;
using AliboboStockLib.date;
using System.Data.Common;
using System.Data;
using AliboboStockLib.util;
using System.Collections;
using AliboboStockLib.fetcher;
using AliboboStockLib.stockdata.inst;
using AliboboStockLib.stockupdater.sbdetail;

namespace AliboboStockLib.stockupdater.sbdetail
{
    public class TseSBDetailUpdater : SBDetailUpdater
    {

        public override String getMarketName()
        {
            return "tse";
        }

        //先準備工作
        protected override void prepareSBTask(DateTime d)
        {
            String ds = DateUtils.getSlashYYYYMMDD(d);
            MyStockDataContext context = new MyStockDataContext();
            List<String> exists = (from sc in context.SBDataTasks where sc.日期.Equals(d) select sc.StockCode).ToList<String>();
            
            //找出當日有交易的
            String sql = "SELECT StockDaily.證券代號 FROM  StockIndex INNER JOIN " +
                                "StockDaily ON StockIndex.代號 = StockDaily.證券代號 " +
                                "where StockIndex.市場='tse' and StockDaily.成交股數 >0 and StockDaily.日期='{0}'  " +
                                "order by StockDaily.證券代號";
            sql = String.Format(sql, ds);
            List<String> allCodes = context.ExecuteQuery<String>(sql).ToList<String>();


            HashSet<String> toCreate = filterToCreate(exists, allCodes);
            //--------------------------------------
            if (toCreate.Count == 0)
                return;
            createSBTask(toCreate,d);
        }
        /*******************************************************************************
         * 
         * 
         * ******************************************************************************/


        



    }
}
